/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 * Date:             2011.08.12                                          *
 *                                                                       *
 *************************************************************************/

#ifndef FreeMAPs_include_COMMON_info_AttributeInfo_h
#define FreeMAPs_include_COMMON_info_AttributeInfo_h

#include "FreeMAPsConfig.h"

//COMMON headers
#include "COMMON/base/StateIndicator.h"
#include "COMMON/tbox/Bimap.h"

namespace FreeMAPs
{

//forward declarations
class Attribute;
class Function;

/**
 * @brief AttributeInfo used to save all attribute's information.
 *
 * a attribute have a name to identity.
 * the concrete information is saved in the Attribute class.
 * one can access the Attribute the attribute's name.
 *
 * @see Attribute.h
 */
class AttributeInfo : public StateIndicator
{
public:

    explicit
    AttributeInfo(
        const std::string& object_name);

    virtual
    ~AttributeInfo();

public:

    inline bool
    is_empty() const;

    /**
     * @return ture iff an attribute with give name exists
     */
    inline bool
    has_attribute (
        const std::string& name) const;

    /**
     * @return the attribute with given name
     * The user should make sure the attribute exists,
     * if not, error will be reported and the program will exit.
     */
    inline const Attribute*
    get_attribute (
        const std::string& name) const;

    inline const std::map<std::string, Attribute*>&
    get_attributes() const;


    inline const Attribute*
    get_default_attribute () const;

    /*
     * @param attribute_name --> attr_Al
     * @param attr_db_file_name --> Al.dat file_path
     */
    void
    add_attribute(
            const std::string attribute_name,
            const std::string attr_db_file_name);

public:

    void
    clear();

    /**
     * @brief build this class from file
     * @param top contains information to build this class
     */
    void
    get_from_input (
        const InputDatabase* db);

    friend std::ostream&
    operator << (
        std::ostream& os,
        /*const*/ AttributeInfo& rhs);

    bool
    check_all_info_db(const InputDatabase* db);


private:

    typedef StateIndicator Parent;

    const Attribute* d_default_attr;

    /*
     * map<attr_name, attr>
     */
    std::map<std::string, Attribute*> d_attrs;

private:

    DISALLOW_COPY_AND_ASSIGN (AttributeInfo);
};

}

#include "COMMON/info/AttributeInfo.inl"

#endif
